package com.android.BluethootChess.connectivity;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.UUID;

import com.android.BluethootChess.util.Utils;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.graphics.Point;

public class BluetoothClient implements IComunication {

	private DataInputStream recv;
	private DataOutputStream send;

	public BluetoothClient() {
		BluetoothSocket socket;
		BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
		BluetoothDevice device = adapter.getRemoteDevice(Utils.getBluetoohServerAddress());
		UUID myUID = UUID.randomUUID();
		try {
			socket = device.createRfcommSocketToServiceRecord(myUID);
			adapter.cancelDiscovery();
			socket.connect();
			recv = new DataInputStream(socket.getInputStream());
			send = new DataOutputStream(socket.getOutputStream());

		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public Point[] getPointsFromServer() {
		return null;
	}

	public Point[] receivePoints() {
		return null;
	}

	public String recvString() {
		String result = "";
		try {
			result = recv.readUTF();
		} catch (Throwable e) {
			Utils.logFile("RecvString error: " + e.toString());
			Utils.logFileError(e);
		}

		return result;
	}

	public void sendPoints(Point[] points) {
		
	}

	public void sendPointsAsString(Point[] points) {
	}

	public void sendString(String string) {
		try {
			Utils.logFile("Se trimite: " + string);
			Utils.logFile("Send_value = " + send);

			send.writeUTF(string.toString());
		} catch (Throwable e) {
			Utils.logFile("SendString error: " + e.toString());
			Utils.logFileError(e);
		}
	}

}
